﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DepartmentSystem
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {

            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string username = TextBox1.Text;
            string password = TextBox2.Text;
            if (username.Length == 0 || password.Length == 0)
            {
                Response.Write("<script>alert('用户名、密码不能为空！')</script>");
                return;
            }

            //string l = "select count(*) cnt from crate where username = '" + username + "' and password = '" + password + "'";
            //if ((int)SQLHelper.QueryScalar(sql) != 1)
            //{
            //    Server.Transfer("Create.aspx");
            //}
            string sql = "select count(*) cnt from tb_user where username = '" + username + "' and password = '" + password + "'";
            if ((int)SQLHelper.QueryScalar(sql) != 1)
            {
                Response.Write("<script>alert('用户名或密码错误!')</script>");
                return;
            }

            Session["username"] = username;
            Server.Transfer("DepartmentInfo.aspx");
        }
        

        protected void Button2_Click(object sender, EventArgs e)
        {
            Server.Transfer("Regist.aspx");
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Server.Transfer("ForgetPassword.aspx");
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            Response.Redirect("Create.aspx");
        }
    }
}